package com.ado.bazinga.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.ado.bazinga.core.dal.entity.Admin;
import com.ado.bazinga.core.manager.AdminManager;
import com.ado.bazinga.core.service.AdminService;

/**
 *@author adonais
 *@date 2020年3月20日
 *@description AdminServiceImpl.java
 **/
@Service(value = "adminService")
public class AdminServiceImpl implements AdminService {

	@Autowired
	@Qualifier("adminManager")
	private AdminManager adminManager ;

	@Override
	public Admin findById(String userId) {
		Admin admin = new Admin() ;
		if (!(StringUtils.isEmpty(userId))) {
			admin = adminManager.findById(userId) ;
		}
		return admin;
	}

	@Override
	public List<Admin> findAll() {
		List<Admin> adminList = adminManager.list() ;
		if (adminList.size() > 0) {
			return adminList ;
		}
		return adminList;
	}

	@Override
	public Admin findByAccount(String account) {
		Admin admin = new Admin() ;
		if(!(StringUtils.isEmpty(account))) {
			admin = adminManager.findByAccount(account) ;
		}
		return admin;
	}

	@Override
	public boolean updateAdmin(Admin admin) {
		boolean flag = adminManager.updateById(admin);
		return flag;
	}

	@Override
	public boolean createAdmin(Admin admin) {
		return adminManager.saveOrUpdate(admin);
	}

	@Override
	@Transactional
	public boolean deleteById(String adminId) {
		boolean flag = adminManager.removeById(Integer.valueOf(adminId)) ;
		return flag;
	}

}
